package org.example.utils;

import com.framework.test.core.BaseTest;
import io.restassured.response.ExtractableResponse;
import io.restassured.response.Response;
import org.example.api.LoginApi;
import org.testng.annotations.BeforeSuite;

import static org.hamcrest.Matchers.equalTo;


public class LoginFixture extends BaseTest {

    @BeforeSuite()
    public void initializeTestSuite2() {
        String username = "fqjlTcaHFdgpTQdpWzInerobfzBEQF7ykEOfRWus29yXbylm/hZEXY94xwWYd5Q+JxKMY+Xk2csom/j9DsDwRrrRVwH7zwYnD2jTFRbBdYoJUx7L/Yp7Qeh5ZmkW2bThsszJKBjd7KN1PNdatVtrx7cpER02yOBHV64nKLGa+O0=";
        String password = "YGAL2iZu9ic/EbMJjeua8cXrhcG+8iEdXJEPncuzESzYH6mfs8hX7s7bzAWuEOTanXjG3qu2OS8X8cDP+Nx5qXy/NgUopq6mCo+tuvuRCgikSzKCvEEllvkVMFetglb3lX9qxT/Xw9gHOUTHmLl1MaTNp5HMs4tcF0ncje2SA70=";
        ExtractableResponse<Response> extractableResponse = LoginApi.login(username, password)
                .then()
                .assertThat()
                .body("code", equalTo(100200))
                .extract();
        String token = extractableResponse.path("data.sessionId");
        String csrfToken = extractableResponse.path("data.csrfToken");
        String lastProjectId = extractableResponse.path("data.lastOrganizationId");
        globalContext.put("x-auth-token", token);
        globalContext.put("csrf-token", csrfToken);
        globalContext.put("lastProjectId", lastProjectId);
    }
}
